package com.car.controller;

import com.car.entity.Coupon;
import com.car.entity.User;
import com.car.service.CouponService;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
 * 
    * @ClassName: CouponController
    * @Description: TODO(优惠卷)
    * @author 郝成浩
    * @date 2018年11月27日
    *
 */
@Controller
@RequestMapping("/coupins")
public class CouponController   {
	@Autowired
	CouponService couponService;

	
	/**
	 * 优惠卷跳转
	    * @Title: coupins
	    * @Description: TODO(这里用一句话描述这个方法的作用)
	    * @param @return    参数
	    * @return String    返回类型
	    * @throws
	 */
	@RequestMapping({"/coupinsJump",""})
	public String coupins(
			@RequestParam(value="userId",required=false)Integer userId,
			@RequestParam(value="types",required=false) Integer types,
			HttpSession session,Model model){
		User user = (User)session.getAttribute("loginSuccess");
		Map<String, Object> maps = (Map<String, Object>)session.getAttribute("mapsToOrderAdd");
		if(types==null){
			types=0;
		}
		
		if(types==1){
			List<Coupon> coupon = couponService.selectAllByuserId(userId);
			model.addAttribute("listCoupon", coupon);
			model.addAttribute("types", types);
			if(maps!=null){
				model.addAttribute("hitid", maps.get("hitid"));
				model.addAttribute("quTime", maps.get("quTime"));
				model.addAttribute("huanTime", maps.get("huanTime"));
				model.addAttribute("huanmd", maps.get("huanmd"));
			}
}else{
		if(user==null){
			model.addAttribute("error", "1");
		}else{
			List<Coupon> coupon = couponService.selectAllByuserId(user.getUserId());
			model.addAttribute("listCoupon", coupon);
			
		}
		
}
	
		return "H5phone/coupons";
	}
	
}